package com.freshcity.page.home
{
	import com.freshcity.common.MainNavWin;
	import com.freshcity.component.container.Component;
	import com.freshcity.component.guide.GuideTipsManager;
	import com.freshcity.core.Dispatcher;
	import com.freshcity.core.OpCodes;
	import com.freshcity.page.wait.ComeInMsg;
	import com.greensock.TweenMax;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class MainNav extends Component
	{
		private var back:MainNavWin;
		private var comeinMsg:ComeInMsg;
		public function MainNav(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
		{
			this.visible = false;
			super(parent, 166, 507);
			
			back.homeLink.addEventListener(MouseEvent.CLICK,onShowHome);
			back.treeLink.addEventListener(MouseEvent.CLICK,onShowTree);
			back.feijiLink.addEventListener(MouseEvent.CLICK,onShowFeiji);
			back.searchLink.addEventListener(MouseEvent.CLICK,onShowSearch);
			back.helpLink.addEventListener(MouseEvent.CLICK,onShowHelp);
		}
		
		public function onShowTree(event:MouseEvent=null):void
		{
			if(!main.treeHome)main.initTree();
			main.treeHome.show();
		}

		public function onShowHelp(event:MouseEvent=null):void
		{
			if (!main.helpHome)main.initHelp();
			main.helpHome.show();
		}
		
		public function onShowSearch(event:MouseEvent=null):void
		{
			if(!main.searchHome)main.initSearch();
			if (main.user.level<=2){
				GuideTipsManager.hideLineBoxTips();
				main.commu.send(OpCodes.GUIDE_DONE, {indexPos:0});
			}
			main.searchHome.show();
		}
		
		public function onShowFeiji(event:MouseEvent=null):void
		{
			if(!main.feijiHome)main.initFeiji();
			main.feijiHome.show();
		}
		
		public function onShowHome(event:MouseEvent=null):void
		{
			if(!main.selfHome)main.initSelf();
			main.selfHome.show();
		}
		
		override protected function addChildren():void
		{
			super.addChildren();
			back = new MainNavWin();
			addChild(back);
		}
		
		override public function destroy():void
		{
			super.destroy();
		}
		
		override public function show(event:Event=null):void
		{
			TweenMax.to(this,0.1,{autoAlpha:1,onComplete:main.postInit});
			
			//在默认房间开始排队等候
			main.commu.send(OpCodes.WAIT_TALK, {room: "1"},onWaitTalk);
			comeinMsg = new ComeInMsg(main);
		}
		
		private function onWaitTalk(data:*):void
		{
			main.commu.send(OpCodes.BEGIN_WAIT, {w: ""},onComeIn);
		}
		
		private function onComeIn(data:*):void
		{
			if(data.user!=main.user.id)comeinMsg.data=data;
		}
	}
}